namespace TfsExtensions.Build.Helper
{
    using System.Globalization;

    /// <summary>
    /// Helper class for parsing
    /// </summary>
    public sealed class ParseHelper
    {
        /// <summary>
        /// Prevents a default instance of the <see cref="ParseHelper"/> class from being created. 
        /// Private constructor ensures class cannot be instantiated.
        /// </summary>
        private ParseHelper()
        {
        }

        /// <summary>
        /// Parse string value to appropriate boolean value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>The parse boolean.</returns>
        public static bool ParseBoolean(string value)
        {
            try
            {
                return bool.Parse(value);
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// Check if the value is a valid positive integer.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>The is valid uint 16 value.</returns>
        public static bool IsValidUnsignedInt16Value(string value)
        {
            bool result = false;
            try
            {
                if (value != null)
                {
                    int item = int.Parse(value, CultureInfo.InvariantCulture);
                    if ((item <= (65535 - 1)) && (item >= 0))
                    {
                        result = true;
                    }
                }
            }
            catch
            {
                result = false;
            }

            return result;
        }
    }
}